package com.lagou.stage03;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class WorkerTest {
    public static void main(String[] args) {
        List<Worker> workers = new ArrayList();
        // 测试题目要求
        // 1. 定义List集合，在List集合中增加三个员工，基本信息如下：  "凤姐" 18 20000  "欧阳峰" 60 8000  "刘德华" 40 30000
        System.out.println("当前员工有" + workers);
        workers.add(new Worker("凤姐", 18, 20000));
        workers.add(new Worker("欧阳锋", 60, 8000));
        workers.add(new Worker("刘德华", 40, 30000));
        System.out.println("当前员工有" + workers);

        // 2. 在"欧阳峰"之前插入一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300
        System.out.println("--------------------------");
        System.out.println("当前员工有" + workers);
        int index = workers.indexOf(new Worker("欧阳锋", 60, 8000));
        workers.add(index, new Worker("张柏芝", 35, 3300));
        System.out.println("当前员工有" + workers);

        // 3. 删除"刘德华"的信息
        System.out.println("--------------------------");
        System.out.println("当前员工有" + workers);
        workers.remove(new Worker("刘德华", 40, 30000));
        System.out.println("当前员工有" + workers);

        // 4. 利用for 循环遍历，打印List 中所有员工的信息
        System.out.println("--------------------------");
        for (int i = 0; i < workers.size(); i++) {
            System.out.println("第" + i + "员工信息是：" + workers.get(i));
        }

        // 5. 利用迭代遍历，对List 中所有的员工调用work 方法
        System.out.println("--------------------------");
        Iterator iterator = workers.iterator();
        while (iterator.hasNext()) {
            for (Worker worker : workers) {
                worker.work();
                iterator.next();
            }
        }

        // 6. 为Worker类重写equals 方法，当姓名、年龄、工资全部相等时候才返回true
        System.out.println("--------------------------");
        Worker w1 = new Worker("凤姐", 18, 20000);
        Worker w2 = new Worker("凤姐", 18, 20000);
        Boolean b = w1.equals(w2);
        System.out.println("员工1的信息：" + w1);
        System.out.println("员工2的信息：" + w2);
        System.out.println("员工1和员工2是否相等：" + b);

        w2 = new Worker("凤姐", 18, 10000);
        b = w1.equals(w2);
        System.out.println("员工1的信息：" + w1);
        System.out.println("员工2的信息：" + w2);
        System.out.println("员工1和员工2是否相等：" + b);

        w2 = new Worker("凤姐", 20, 20000);
        b = w1.equals(w2);
        System.out.println("员工1的信息：" + w1);
        System.out.println("员工2的信息：" + w2);
        System.out.println("员工1和员工2是否相等：" + b);

        w2 = new Worker("二凤", 18, 20000);
        b = w1.equals(w2);
        System.out.println("员工1的信息：" + w1);
        System.out.println("员工2的信息：" + w2);
        System.out.println("员工1和员工2是否相等：" + b);


    }
}
